import { getUserMenu } from "@/api/menuManagement"

import { addRouters } from "@/utils/index"
import { Row } from "element-ui"

const state = {
    menus: [],
    router: []

}


const mutations = {
    SET_ROUTER: (state, route) => {
        state.router = route
    }
}


const actions = {
    getMenuData({ commit }) {
        return new Promise((resolve, reject) => {
            // let data = {
            //     page: 1,
            //     size: 1
            // }
            getUserMenu().then(res => {
                const data = res.data
                const rou = addRouters(data)
                rou.push({ path: '*', redirect: '/404', hidden: true })
                commit('SET_ROUTER', rou)
                resolve(rou)
            })
        }).catch(error => {
            reject(error)
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}

